import { utils } from '@ohif/core';

const { studyMetadataManager } = utils;

export default function(viewportSpecificData = {}, activeViewportIndex) {
  if (!viewportSpecificData[activeViewportIndex]) {
    return false;
  };

  const { displaySetInstanceUID, StudyInstanceUID } = viewportSpecificData[
    activeViewportIndex
  ];

  const studies = studyMetadataManager.all();

  const study = studies.find(
    study => study.studyInstanceUID === StudyInstanceUID
  );

  if (!study) {
    return false;
  }

  const displaySet = study._displaySets.find(set => set.displaySetInstanceUID === displaySetInstanceUID);

  if (!displaySet) {
    return false;
  };

  return displaySet.isReconstructable;
};
